/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.game.math.view.action;

import javax.swing.Action;
import org.game.math.view.config.Configure;
import org.game.math.view.expression.Operator;

/**
 *
 * @author nmduc
 */
class ActionManager {

  private var actionMap:Map[String, Action]  = Map();
  private var actionOpMap:Map[Enumeration#Value, Action]  = Map();

  private val configure:Configure = Configure.getInstance();

  actionMap += ActionManager.NEW_ACTION -> new NewGameAction();
  actionMap+=ActionManager.CHECK_ACTION -> new CheckGameAction();
  val addOperatorAction:AddOperatorAction = new AddOperatorAction(configure);
  actionMap+=ActionManager.ADD_ACTION-> addOperatorAction;
  actionOpMap+=Operator.ADD-> addOperatorAction;
  val subOperatorAction:SubOperatorAction = new SubOperatorAction(configure);
  actionMap+=ActionManager.SUB_ACTION-> subOperatorAction;
  actionOpMap+=Operator.SUB-> subOperatorAction;
  val mulOperatorAction:MulOperatorAction = new MulOperatorAction(configure);
  actionMap+=ActionManager.MUL_ACTION-> mulOperatorAction;
  actionOpMap+=Operator.MUL-> mulOperatorAction;
  val divOperatorAction:DivOperatorAction = new DivOperatorAction(configure);
  actionMap+=ActionManager.DIV_ACTION-> divOperatorAction;
  actionOpMap+=Operator.DIV-> divOperatorAction;
  val mulTableAction:MulTableAction  = new MulTableAction(configure);
  actionMap+=ActionManager.MUL_TABLE_ACTION-> mulTableAction;
  val preferenceAction:PreferenceAction = new PreferenceAction();
  actionMap+=ActionManager.PREFERENCE_ACTION-> preferenceAction;

  configure.addObserver(addOperatorAction);
  configure.addObserver(subOperatorAction);
  configure.addObserver(mulOperatorAction);
  configure.addObserver(divOperatorAction);


  def getAction(actionKey:String):Action = {
    actionMap.get(actionKey).getOrElse(null);
  }

  def getAction(operator:Enumeration#Value):Action  = {
    actionOpMap.get(operator).getOrElse(null);
  }

}

object ActionManager {
  val NEW_ACTION:String = "NEW_ACTION";
  val CHECK_ACTION:String = "CHECK_ACTION";
  val ADD_ACTION:String = "ADD_ACTION";
  val SUB_ACTION:String = "SUB_ACTION";
  val MUL_ACTION:String = "MUL_ACTION";
  val DIV_ACTION:String = "DIV_ACTION";
  val MUL_TABLE_ACTION:String = "MUL_TABLE_ACTION";
  val PREFERENCE_ACTION:String = "PREFERENCE_ACTION";
  val actionManager:ActionManager = new ActionManager();
  def getInstance():ActionManager = {
    actionManager;
  }
}
